package com.yuqing.sentimentapp.workspace.festival.action;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.widget.PopupMenu;
import android.text.TextUtils;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.androidkun.xtablayout.XTabLayout;
import com.linkface.baselibrary.http.BaseBean;
import com.linkface.baselibrary.utils.FileUtils;
import com.linkface.baselibrary.utils.ThreadManager;
import com.yuqing.sentimentapp.R;
import com.yuqing.sentimentapp.base.BaseActivity;
import com.yuqing.sentimentapp.base.BaseObserver;
import com.yuqing.sentimentapp.module.DownloadPdfHelp;
import com.yuqing.sentimentapp.module.ModuleManager;
import com.yuqing.sentimentapp.utils.ToastUtil;
import com.yuqing.sentimentapp.workspace.festival.action.entity.FestivalActionInfoResult;
import com.yuqing.sentimentapp.workspace.festival.action.entity.FestivalActionReportResult;
import com.yuqing.sentimentapp.workspace.festival.action.entity.FestivalUnitInfoResult;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by shenhe on 2020/4/3.
 */
public class FestivalActionFillInActivity extends BaseActivity {

    @BindView(R.id.iv_back)
    ImageView mIvBack;
    @BindView(R.id.tv_save)
    TextView mTvSave;
    @BindView(R.id.tabs)
    XTabLayout mTabs;
    @BindView(R.id.ll_festival)
    LinearLayout llFestival;
    @BindView(R.id.tv_festival)
    TextView tvFestival;
    @BindView(R.id.et_fire_count)
    EditText mEtFireCount;
    @BindView(R.id.et_fire_dead_count)
    EditText mEtFireDeadCount;
    @BindView(R.id.et_fire_injured_count)
    EditText mEtFireInjuredCount;
    @BindView(R.id.et_fire_loss_count)
    EditText mEtFireLossCount;
    @BindView(R.id.et_tmp_point_count)
    EditText mEtTmpPointCount;
    @BindView(R.id.et_tmp_car_count)
    EditText mEtTmpCarCount;
    @BindView(R.id.et_tmp_people_count)
    EditText mEtTmpPeopleCount;
    @BindView(R.id.et_fsfo_team_count)
    EditText mEtFsfoTeamCount;
    @BindView(R.id.et_fsfo_check_count)
    EditText mEtFsfoCheckCount;
    @BindView(R.id.et_fsfo_discovery_count)
    EditText mEtFsfoDiscoveryCount;
    @BindView(R.id.et_fsfo_rectify_count)
    EditText mEtFsfoRectifyCount;
    @BindView(R.id.et_fsfo_close_count)
    EditText mEtFsfoCloseCount;
    @BindView(R.id.et_fsfo_ban_count)
    EditText mEtFsfoBanCount;
    @BindView(R.id.et_fsfo_propagate_count)
    EditText mEtFsfoPropagateCount;
    @BindView(R.id.et_fsfo_broadcast_count)
    EditText mEtFsfoBroadcastCount;
    @BindView(R.id.et_fsfo_message_count)
    EditText mEtFsfoMessageCount;
    @BindView(R.id.et_action_outfire_count)
    EditText mEtActionOutfireCount;
    @BindView(R.id.et_action_er_count)
    EditText mEtActionErCount;
    @BindView(R.id.et_car_outfire_count)
    EditText mEtCarOutfireCount;
    @BindView(R.id.et_car_er_count)
    EditText mEtCarErCount;
    @BindView(R.id.et_people_outfire_count)
    EditText mEtPeopleOutfireCount;
    @BindView(R.id.et_people_er_count)
    EditText mEtPeopleErCount;
    @BindView(R.id.et_save_outfire_count)
    EditText mEtSaveOutfireCount;
    @BindView(R.id.et_save_er_count)
    EditText mEtSaveErCount;
    @BindView(R.id.et_evacuate_outfire_count)
    EditText mEtEvacuateOutfireCount;
    @BindView(R.id.et_evacuate_er_count)
    EditText mEtEvacuateErCount;
    @BindView(R.id.et_property_outfire_count)
    EditText mEtPropertyOutfireCount;
    @BindView(R.id.et_property_er_count)
    EditText mEtPropertyErCount;
    @BindView(R.id.et_patrol_car_count)
    EditText mEtPatrolCarCount;
    @BindView(R.id.et_patrol_people_count)
    EditText mEtPatrolPeopleCount;
    @BindView(R.id.et_drill_count)
    EditText mEtDrillCount;
    @BindView(R.id.et_duty_point_count)
    EditText mEtDutyPointCount;
    @BindView(R.id.ll_fsfo)
    LinearLayout mLlFsfo;
    @BindView(R.id.ll_outfire)
    LinearLayout mLlOutfire;

    private boolean editEnable = true;
    private FestivalActionInfoResult.DataBean actionInfo;
    private ArrayList<FestivalActionReportResult.DataBean.FestivalsBean> festivals;
    private FestivalActionReportResult.DataBean.SubSumBean subSum;
    /**
     * 从已上报列表跳转过来的
     */
    private FestivalActionReportResult.DataBean.ReportsBean reportsInfo;

    public static void goActivity(Activity activity, FestivalActionInfoResult.DataBean actionInfo, FestivalActionReportResult.DataBean.SubSumBean subSum, ArrayList<FestivalActionReportResult.DataBean.FestivalsBean> festivals) {
        Intent intent = new Intent(activity, FestivalActionFillInActivity.class);
        intent.putExtra("actionInfo", actionInfo);
        intent.putExtra("subSum", subSum);
        intent.putExtra("festivals", festivals);
        activity.startActivity(intent);
    }
    public static void goActivity(Activity activity, FestivalActionReportResult.DataBean.ReportsBean reportsInfo, ArrayList<FestivalActionReportResult.DataBean.FestivalsBean> festivals) {
        Intent intent = new Intent(activity, FestivalActionFillInActivity.class);
        intent.putExtra("reportsInfo", reportsInfo);
        intent.putExtra("festivals", festivals);
        activity.startActivity(intent);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_festival_action_fill_in;
    }

    @Override
    public void initPresenter() {
        Intent intent = getIntent();
        if (intent == null) return;
        actionInfo = ((FestivalActionInfoResult.DataBean) intent.getSerializableExtra("actionInfo"));
        subSum = ((FestivalActionReportResult.DataBean.SubSumBean) intent.getSerializableExtra("subSum"));
        festivals = ((ArrayList<FestivalActionReportResult.DataBean.FestivalsBean>) intent.getSerializableExtra("festivals"));

        reportsInfo = ((FestivalActionReportResult.DataBean.ReportsBean) intent.getSerializableExtra("reportsInfo"));

    }

    @SuppressLint("CheckResult")
    @Override
    public void initView() {
        if (actionInfo != null) {
            mEtFireCount.setText(actionInfo.getFireCount());
            mEtFireDeadCount.setText(actionInfo.getFireDeadCount());
            mEtFireInjuredCount.setText(actionInfo.getFireInjuredCount());
            mEtFireLossCount.setText(actionInfo.getFireLossCount());
            mEtTmpCarCount.setText(actionInfo.getTmpCarCount());
            mEtTmpPeopleCount.setText(actionInfo.getTmpPeopleCount());
            mEtTmpPointCount.setText(actionInfo.getTmpPointCount());
            mEtFsfoBanCount.setText(actionInfo.getFsfoBanCount());
            mEtFsfoBroadcastCount.setText(actionInfo.getFsfoBroadcastCount());
            mEtFsfoCheckCount.setText(actionInfo.getFsfoCheckCount());
            mEtFsfoCloseCount.setText(actionInfo.getFsfoCloseCount());
            mEtFsfoDiscoveryCount.setText(actionInfo.getFsfoDiscoveryCount());
            mEtFsfoMessageCount.setText(actionInfo.getFsfoMessageCount());
            mEtFsfoPropagateCount.setText(actionInfo.getFsfoPropagateCount());
            mEtFsfoRectifyCount.setText(actionInfo.getFsfoRectifyCount());
            mEtFsfoTeamCount.setText(actionInfo.getFsfoTeamCount());
            mEtActionErCount.setText(actionInfo.getActionErCount());
            mEtActionOutfireCount.setText(actionInfo.getActionOutfireCount());
            mEtCarErCount.setText(actionInfo.getCarErCount());
            mEtCarOutfireCount.setText(actionInfo.getCarOutfireCount());
            mEtPeopleErCount.setText(actionInfo.getPeopleErCount());
            mEtPeopleOutfireCount.setText(actionInfo.getPeopleOutfireCount());
            mEtSaveErCount.setText(actionInfo.getSaveErCount());
            mEtSaveOutfireCount.setText(actionInfo.getSaveOutfireCount());
            mEtEvacuateErCount.setText(actionInfo.getEvacuateErCount());
            mEtEvacuateOutfireCount.setText(actionInfo.getEvacuateOutfireCount());
            mEtPropertyErCount.setText(actionInfo.getPropertyErCount());
            mEtPropertyOutfireCount.setText(actionInfo.getPropertyOutfireCount());
            mEtPatrolCarCount.setText(actionInfo.getPatrolCarCount());
            mEtPatrolPeopleCount.setText(actionInfo.getPatrolPeopleCount());
            mEtDrillCount.setText(actionInfo.getDrillCount());
            mEtDutyPointCount.setText(actionInfo.getDutyPointCount());

            if (festivals != null) {
                Observable.fromIterable(festivals).filter(festivalsBean -> TextUtils.equals(actionInfo.getFestival(), festivalsBean.getId())).subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(festivalsBean -> {
                            tvFestival.setText(festivalsBean.getName());
                            tvFestival.setTag(festivalsBean.getId());
                        });
            }
        } else {
            if (subSum != null) {
                mEtFireCount.setText(subSum.getFireCount());
                mEtFireDeadCount.setText(subSum.getFireDeadCount());
                mEtFireInjuredCount.setText(subSum.getFireInjuredCount());
                mEtFireLossCount.setText(subSum.getFireLossCount());

                mEtTmpCarCount.setText(subSum.getTmpCarCount());
                mEtTmpPeopleCount.setText(subSum.getTmpPeopleCount());
                mEtTmpPointCount.setText(subSum.getTmpPointCount());

                mEtFsfoBanCount.setText(subSum.getFsfoBanCount());
                mEtFsfoBroadcastCount.setText(subSum.getFsfoBroadcastCount());
                mEtFsfoCheckCount.setText(subSum.getFsfoCheckCount());
                mEtFsfoCloseCount.setText(subSum.getFsfoCloseCount());
                mEtFsfoDiscoveryCount.setText(subSum.getFsfoDiscoveryCount());
                mEtFsfoMessageCount.setText(subSum.getFsfoMessageCount());
                mEtFsfoPropagateCount.setText(subSum.getFsfoPropagateCount());
                mEtFsfoRectifyCount.setText(subSum.getFsfoRectifyCount());
                mEtFsfoTeamCount.setText(subSum.getFsfoTeamCount());

                mEtActionErCount.setText(subSum.getActionErCount());
                mEtActionOutfireCount.setText(subSum.getActionOutfireCount());

                mEtCarErCount.setText(subSum.getCarErCount());
                mEtCarOutfireCount.setText(subSum.getCarOutfireCount());

                mEtPeopleErCount.setText(subSum.getPeopleErCount());
                mEtPeopleOutfireCount.setText(subSum.getPeopleOutfireCount());

                mEtSaveErCount.setText(subSum.getSaveErCount());
                mEtSaveOutfireCount.setText(subSum.getSaveOutfireCount());

                mEtEvacuateErCount.setText(subSum.getEvacuateErCount());
                mEtEvacuateOutfireCount.setText(subSum.getEvacuateOutfireCount());

                mEtPropertyErCount.setText(subSum.getPropertyErCount());
                mEtPropertyOutfireCount.setText(subSum.getPropertyOutfireCount());

                mEtPatrolCarCount.setText(subSum.getPatrolCarCount());
                mEtPatrolPeopleCount.setText(subSum.getPatrolPeopleCount());

                mEtDrillCount.setText(subSum.getDrillCount());
                mEtDutyPointCount.setText(subSum.getDutyPointCount());

                if (festivals != null) {
                    Observable.fromIterable(festivals).filter(festivalsBean -> TextUtils.equals(subSum.getFestival(), festivalsBean.getId())).subscribeOn(Schedulers.io())
                            .observeOn(AndroidSchedulers.mainThread())
                            .subscribe(festivalsBean -> {
                                tvFestival.setText(festivalsBean.getName());
                                tvFestival.setTag(festivalsBean.getId());
                            });
                }
            }
        }

        /**
         * 从已上报列表跳转过来的，不可编辑，隐藏保存按钮
         */
        if (reportsInfo != null) {
            mEtFireCount.setText(reportsInfo.getFireCount());
            mEtFireDeadCount.setText(reportsInfo.getFireDeadCount());
            mEtFireInjuredCount.setText(reportsInfo.getFireInjuredCount());
            mEtFireLossCount.setText(reportsInfo.getFireLossCount());
            mEtTmpCarCount.setText(reportsInfo.getTmpCarCount());
            mEtTmpPeopleCount.setText(reportsInfo.getTmpPeopleCount());
            mEtTmpPointCount.setText(reportsInfo.getTmpPointCount());
            mEtFsfoBanCount.setText(reportsInfo.getFsfoBanCount());
            mEtFsfoBroadcastCount.setText(reportsInfo.getFsfoBroadcastCount());
            mEtFsfoCheckCount.setText(reportsInfo.getFsfoCheckCount());
            mEtFsfoCloseCount.setText(reportsInfo.getFsfoCloseCount());
            mEtFsfoDiscoveryCount.setText(reportsInfo.getFsfoDiscoveryCount());
            mEtFsfoMessageCount.setText(reportsInfo.getFsfoMessageCount());
            mEtFsfoPropagateCount.setText(reportsInfo.getFsfoPropagateCount());
            mEtFsfoRectifyCount.setText(reportsInfo.getFsfoRectifyCount());
            mEtFsfoTeamCount.setText(reportsInfo.getFsfoTeamCount());
            mEtActionErCount.setText(reportsInfo.getActionErCount());
            mEtActionOutfireCount.setText(reportsInfo.getActionOutfireCount());
            mEtCarErCount.setText(reportsInfo.getCarErCount());
            mEtCarOutfireCount.setText(reportsInfo.getCarOutfireCount());
            mEtPeopleErCount.setText(reportsInfo.getPeopleErCount());
            mEtPeopleOutfireCount.setText(reportsInfo.getPeopleOutfireCount());
            mEtSaveErCount.setText(reportsInfo.getSaveErCount());
            mEtSaveOutfireCount.setText(reportsInfo.getSaveOutfireCount());
            mEtEvacuateErCount.setText(reportsInfo.getEvacuateErCount());
            mEtEvacuateOutfireCount.setText(reportsInfo.getEvacuateOutfireCount());
            mEtPropertyErCount.setText(reportsInfo.getPropertyErCount());
            mEtPropertyOutfireCount.setText(reportsInfo.getPropertyOutfireCount());
            mEtPatrolCarCount.setText(reportsInfo.getPatrolCarCount());
            mEtPatrolPeopleCount.setText(reportsInfo.getPatrolPeopleCount());
            mEtDrillCount.setText(reportsInfo.getDrillCount());
            mEtDutyPointCount.setText(reportsInfo.getDutyPointCount());

            if (festivals != null) {
                Observable.fromIterable(festivals).filter(festivalsBean -> TextUtils.equals(reportsInfo.getFestival(), festivalsBean.getId())).subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(festivalsBean -> {
                            tvFestival.setText(festivalsBean.getName());
                            tvFestival.setTag(festivalsBean.getId());
                        });
            }
            mEtFireCount.setEnabled(false);
            mEtFireDeadCount.setEnabled(false);
            mEtFireInjuredCount.setEnabled(false);
            mEtFireLossCount.setEnabled(false);

            mEtTmpCarCount.setEnabled(false);
            mEtTmpPeopleCount.setEnabled(false);
            mEtTmpPointCount.setEnabled(false);

            mEtFsfoBanCount.setEnabled(false);
            mEtFsfoBroadcastCount.setEnabled(false);
            mEtFsfoCheckCount.setEnabled(false);
            mEtFsfoCloseCount.setEnabled(false);
            mEtFsfoDiscoveryCount.setEnabled(false);
            mEtFsfoMessageCount.setEnabled(false);
            mEtFsfoPropagateCount.setEnabled(false);
            mEtFsfoRectifyCount.setEnabled(false);
            mEtFsfoTeamCount.setEnabled(false);

            mEtActionErCount.setEnabled(false);
            mEtActionOutfireCount.setEnabled(false);

            mEtCarErCount.setEnabled(false);
            mEtCarOutfireCount.setEnabled(false);

            mEtPeopleErCount.setEnabled(false);
            mEtPeopleOutfireCount.setEnabled(false);

            mEtSaveErCount.setEnabled(false);
            mEtSaveOutfireCount.setEnabled(false);

            mEtEvacuateErCount.setEnabled(false);
            mEtEvacuateOutfireCount.setEnabled(false);

            mEtPropertyErCount.setEnabled(false);
            mEtPropertyOutfireCount.setEnabled(false);

            mEtPatrolCarCount.setEnabled(false);
            mEtPatrolPeopleCount.setEnabled(false);

            mEtDrillCount.setEnabled(false);
            mEtDutyPointCount.setEnabled(false);

            llFestival.setClickable(false);

            mTvSave.setVisibility(View.GONE);
        }

        mTabs.setOnTabSelectedListener(new XTabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(XTabLayout.Tab tab) {
                resetView();
                if (tab.getPosition() == 0) {
                    mLlFsfo.setVisibility(View.VISIBLE);
                } else if (tab.getPosition() == 1) {
                    mLlOutfire.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void onTabUnselected(XTabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(XTabLayout.Tab tab) {

            }
        });
    }

    private void resetView() {
        mLlFsfo.setVisibility(View.GONE);
        mLlOutfire.setVisibility(View.GONE);
    }

    @OnClick({R.id.iv_back, R.id.ll_festival, R.id.tv_save})
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.iv_back:
                finish();
                break;
            case R.id.ll_festival:
                if (festivals == null || festivals.size() == 0) return;
                PopupMenu popupMenu = new PopupMenu(this, llFestival);
                Menu menu_more = popupMenu.getMenu();

                for (int i = 0; i < festivals.size(); i++) {
                    menu_more.add(Menu.NONE, i, i, festivals.get(i).getName());
                }
                popupMenu.setOnMenuItemClickListener(menuItem -> {
                    int i = menuItem.getItemId();
                    tvFestival.setText(festivals.get(i).getName());
                    tvFestival.setTag(festivals.get(i).getId());
                    return true;
                });
                popupMenu.show();
                break;

            case R.id.tv_save:
                String festival = tvFestival.getText().toString();
                if (TextUtils.isEmpty(festival)) {
                    ToastUtil.showShort("请选择上报节日");
                    return;
                }
                if (actionInfo == null) {
                    actionInfo = new FestivalActionInfoResult.DataBean();
                    setData();
                    saveFestivalActionInfo(actionInfo);
                } else {
                    setData();
                    updateFestivalActionInfo(actionInfo);
                }
                break;
        }
    }

    private void setData() {
        actionInfo.setFestival(tvFestival.getTag().toString());
        actionInfo.setFireCount(TextUtils.isEmpty(mEtFireCount.getText().toString()) ? "0" : mEtFireCount.getText().toString());
        actionInfo.setFireDeadCount(TextUtils.isEmpty(mEtFireDeadCount.getText().toString()) ? "0" : mEtFireDeadCount.getText().toString());
        actionInfo.setFireInjuredCount(TextUtils.isEmpty(mEtFireInjuredCount.getText().toString()) ? "0" : mEtFireInjuredCount.getText().toString());
        actionInfo.setFireLossCount(TextUtils.isEmpty(mEtFireLossCount.getText().toString()) ? "0" : mEtFireLossCount.getText().toString());
        actionInfo.setTmpCarCount(TextUtils.isEmpty(mEtTmpCarCount.getText().toString()) ? "0" : mEtTmpCarCount.getText().toString());
        actionInfo.setTmpPeopleCount(TextUtils.isEmpty(mEtTmpPeopleCount.getText().toString()) ? "0" : mEtTmpPeopleCount.getText().toString());
        actionInfo.setTmpPointCount(TextUtils.isEmpty(mEtTmpPointCount.getText().toString()) ? "0" : mEtTmpPointCount.getText().toString());
        actionInfo.setFsfoTeamCount(TextUtils.isEmpty(mEtFsfoTeamCount.getText().toString()) ? "0" : mEtFsfoTeamCount.getText().toString());
        actionInfo.setFsfoCheckCount(TextUtils.isEmpty(mEtFsfoCheckCount.getText().toString()) ? "0" : mEtFsfoCheckCount.getText().toString());
        actionInfo.setFsfoBanCount(TextUtils.isEmpty(mEtFsfoBanCount.getText().toString()) ? "0" : mEtFsfoBanCount.getText().toString());
        actionInfo.setFsfoBroadcastCount(TextUtils.isEmpty(mEtFsfoBroadcastCount.getText().toString()) ? "0" : mEtFsfoBroadcastCount.getText().toString());
        actionInfo.setFsfoCloseCount(TextUtils.isEmpty(mEtFsfoCloseCount.getText().toString()) ? "0" : mEtFsfoCloseCount.getText().toString());
        actionInfo.setFsfoDiscoveryCount(TextUtils.isEmpty(mEtFsfoDiscoveryCount.getText().toString()) ? "0" : mEtFsfoDiscoveryCount.getText().toString());
        actionInfo.setFsfoMessageCount(TextUtils.isEmpty(mEtFsfoMessageCount.getText().toString()) ? "0" : mEtFsfoMessageCount.getText().toString());
        actionInfo.setFsfoPropagateCount(TextUtils.isEmpty(mEtFsfoPropagateCount.getText().toString()) ? "0" : mEtFsfoPropagateCount.getText().toString());
        actionInfo.setFsfoRectifyCount(TextUtils.isEmpty(mEtFsfoRectifyCount.getText().toString()) ? "0" : mEtFsfoRectifyCount.getText().toString());
        actionInfo.setActionOutfireCount(TextUtils.isEmpty(mEtActionOutfireCount.getText().toString()) ? "0" : mEtActionOutfireCount.getText().toString());
        actionInfo.setActionErCount(TextUtils.isEmpty(mEtActionErCount.getText().toString()) ? "0" : mEtActionErCount.getText().toString());
        actionInfo.setCarErCount(TextUtils.isEmpty(mEtCarErCount.getText().toString()) ? "0" : mEtCarErCount.getText().toString());
        actionInfo.setCarOutfireCount(TextUtils.isEmpty(mEtCarOutfireCount.getText().toString()) ? "0" : mEtCarOutfireCount.getText().toString());
        actionInfo.setPeopleErCount(TextUtils.isEmpty(mEtPeopleErCount.getText().toString()) ? "0" : mEtPeopleErCount.getText().toString());
        actionInfo.setPeopleOutfireCount(TextUtils.isEmpty(mEtPeopleOutfireCount.getText().toString()) ? "0" : mEtPeopleOutfireCount.getText().toString());
        actionInfo.setSaveErCount(TextUtils.isEmpty(mEtSaveErCount.getText().toString()) ? "0" : mEtSaveErCount.getText().toString());
        actionInfo.setSaveOutfireCount(TextUtils.isEmpty(mEtSaveOutfireCount.getText().toString()) ? "0" : mEtSaveOutfireCount.getText().toString());
        actionInfo.setEvacuateErCount(TextUtils.isEmpty(mEtEvacuateErCount.getText().toString()) ? "0" : mEtEvacuateErCount.getText().toString());
        actionInfo.setEvacuateOutfireCount(TextUtils.isEmpty(mEtEvacuateOutfireCount.getText().toString()) ? "0" : mEtEvacuateOutfireCount.getText().toString());
        actionInfo.setPropertyErCount(TextUtils.isEmpty(mEtPropertyErCount.getText().toString()) ? "0" : mEtPropertyErCount.getText().toString());
        actionInfo.setPropertyOutfireCount(TextUtils.isEmpty(mEtPropertyOutfireCount.getText().toString()) ? "0" : mEtPropertyOutfireCount.getText().toString());
        actionInfo.setPatrolCarCount(TextUtils.isEmpty(mEtPatrolCarCount.getText().toString()) ? "0" : mEtPatrolCarCount.getText().toString());
        actionInfo.setPatrolPeopleCount(TextUtils.isEmpty(mEtPatrolPeopleCount.getText().toString()) ? "0" : mEtPatrolPeopleCount.getText().toString());
        actionInfo.setDrillCount(TextUtils.isEmpty(mEtDrillCount.getText().toString()) ? "0" : mEtDrillCount.getText().toString());
        actionInfo.setDutyPointCount(TextUtils.isEmpty(mEtDutyPointCount.getText().toString()) ? "0" : mEtDutyPointCount.getText().toString());
    }

    public void saveFestivalActionInfo(FestivalActionInfoResult.DataBean actionInfo) {
        ModuleManager.getInstance().saveFestivalActionReportInfoResult(actionInfo)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseBean>() {
                    @Override
                    protected void hideDialog() {
                        startProgressDialog();
                    }

                    @Override
                    protected void showDialog() {
                        stopProgressDialog();
                    }

                    @Override
                    protected void onSuccess(BaseBean baseBean) {
                        showShortToast("保存成功");
                        finish();
                    }

                    @Override
                    protected void onFailure(String message) {
                        showShortToast(message);
                    }
                });
    }

    public void updateFestivalActionInfo(FestivalActionInfoResult.DataBean actionInfo) {
        ModuleManager.getInstance().updateFestivalActionReportInfoResult(actionInfo)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseBean>() {
                    @Override
                    protected void hideDialog() {
                        stopProgressDialog();
                    }

                    @Override
                    protected void showDialog() {
                        startProgressDialog();
                    }

                    @Override
                    protected void onSuccess(BaseBean baseBean) {
                        showShortToast("保存成功");
                        finish();
                    }

                    @Override
                    protected void onFailure(String message) {
                        showShortToast(message);
                    }
                });
    }
}
